<template>

  <!-- table区域-begin -->
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys,type:'radio', onChange: onSelectChange}"
      @change="handleTableChange">

    </a-table>
  </div>
</template>

<script>

  import {YcListMixin} from '@/mixins/YcListMixin'
  import YchConstant from "@/api/YchConstant";
  import { getAction } from '@/api/manage'

  export default {
    name: "SysPositionList",
    mixins: [YcListMixin],
    components: {},
    props: {
      positionId: String
    },
    data() {
      return {
        description: '职务选择',
        // 表头
        columns: [
          {
            title:this.$t('m.system.position.entity.positionName'),
            align: "center",
            dataIndex: 'positionName',
            width: 180
          },
          {
            title: this.$t('m.system.position.entity.positionCode'),
            align: "center",
            dataIndex: 'positionCode',
            width: 140
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/sysPosition/list"
        },
        dictOptions: {},
        /* 排序参数 */
        isorter: {
          column: 'positionOrder',
          order: 'asc',
        },
        ipagination: {
          pageSize: 20,
          showQuickJumper: false,
          showSizeChanger: false,
          total: 0
        },
      }
    },
    created(){
      this.loadData(1)
    },
    methods: {
      loadData (arg) {
        if (!this.url.list) {
          this.messageUtil.error('请设置url.list属性!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams()//查询条件


        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
            if(this.positionId){
              this.selectionRows = this.dataSource.filter(item=>item.id==this.positionId)
              this.selectedRowKeys = this.selectionRows.map(item=>{
                return item.id
              })
            }
          }else {
            this.messageUtil.warning(res.message)
          }
          this.loading = false
        })
      },
    }
  }
</script>
<style lang="less" scoped>

</style>
